package com.swyc.osschat.Test.designMode.xiangYuan.fac;

import com.swyc.osschat.Test.designMode.xiangYuan.base.ChessPieces;
import com.swyc.osschat.Test.designMode.xiangYuan.impl.BlackPieces;
import com.swyc.osschat.Test.designMode.xiangYuan.impl.WhitePieces;

import java.util.HashMap;

/**
 * @description 享元工厂角色：
 * @Author: z156940l@outlook.com
 * @className PiecesFactory
 * @Date: 2022/7/25 22:53
 */
public class PiecesFactory {
    //存储棋子
    private HashMap<String, ChessPieces> map;

    //初始化
    private PiecesFactory(){
        map = new HashMap<>();
        map.put("black",new BlackPieces());
        map.put("white",new WhitePieces());
    }

    //单例模式
    public static PiecesFactory instance = new PiecesFactory();

    public static PiecesFactory getInstance(){
        return instance;
    }

    //获取棋子
    public ChessPieces getPieces(String type){
        return map.get(type);
    }
}
